Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | import { Metadata } from "next"; import { notFound } from "next/navigation"; import Link from "next/link"; import { prisma } from "@/lib/prisma"; import { formatCurrency } from "@/lib/core"; type Props = { params: Promise<{ id: string }>; }; export async function generateMetadata({ params }: Props): Promise<Metadata> { const { id } = await params; return { title: `Order #${id} Confirmation | Elite Events`, description: "Your order has been confirmed"}; } async function OrderConfirmationPage({ params }: Props) { const { id } = await params; const orderId = parseInt(id); if (isNaN(orderId)) { notFound(); } const order = await prisma.order.findUnique({ where: { id: orderId }, include: { items: { include: { product: true }}, user: { select: { email: true, name: true }}}}); if (!order) { notFound(); } const shippingAddress = JSON.parse(order.shippingAddress || "{}"); const billingAddress = JSON.parse(order.billingAddress || "{}"); const formatDate = (date: Date) => { return new Date(date).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric"}); }; const getStatusColor = (status: string) => { switch (status) { case "PROCESSING": return "bg-blue-50 text-blue-700 border-blue-200"; case "SHIPPED": return "bg-green-50 text-green-700 border-green-200"; case "DELIVERED": return "bg-green-50 text-green-700 border-green-200"; case "CANCELLED": return "bg-red-50 text-red-700 border-red-200"; default: return "bg-gray-50 text-gray-700 border-gray-200"; } }; const getStatusIcon = (status: string) => { switch (status) { case "PROCESSING": return "⏳"; case "SHIPPED": return "📦"; case "DELIVERED": return "✓"; case "CANCELLED": return "✕"; default: return "•"; } }; return ( <> <section className="overflow-hidden pt-[140px] pb-20 bg-gray-2"> <div className="max-w-[1170px] w-full mx-auto px-4 sm:px-8 xl:px-0"> {/* Success Message */} <div className="bg-white shadow-1 rounded-[10px] p-4 sm:p-8.5 mb-7.5"> <div className="flex items-center justify-center mb-4"> <div className="text-5xl text-green">✓</div> </div> <h1 className="text-3xl font-bold text-center mb-2"> Thank You for Your Order! </h1> <p className="text-center text-gray-5"> Your order has been confirmed and is being prepared for shipment. </p> </div> <div className="grid grid-cols-1 lg:grid-cols-3 gap-7.5"> {/* Order Details - Left Column */} <div className="lg:col-span-2 space-y-7.5"> {/* Order Info Card */} <div className="bg-white shadow-1 rounded-[10px] p-4 sm:p-8.5"> <h2 className="font-medium text-xl text-dark mb-5"> Order Information </h2> <div className="grid grid-cols-2 sm:grid-cols-4 gap-4"> <div> <p className="text-sm text-gray-5 mb-1">Order Number</p> <p className="font-bold text-dark text-lg">#{order.id}</p> </div> <div> <p className="text-sm text-gray-5 mb-1">Order Date</p> <p className="font-medium text-dark"> {formatDate(order.createdAt)} </p> </div> <div> <p className="text-sm text-gray-5 mb-1">Status</p> <div className={`inline-flex items-center gap-1 px-3 py-1 rounded-full border ${getStatusColor(order.status)} text-sm font-medium`} > <span>{getStatusIcon(order.status)}</span> <span className="capitalize">{order.status}</span> </div> </div> <div> <p className="text-sm text-gray-5 mb-1">Email</p> <p className="font-medium text-dark text-sm"> {order.user?.email} </p> </div> </div> </div> {/* Order Items */} <div className="bg-white shadow-1 rounded-[10px] p-4 sm:p-8.5"> <h2 className="font-medium text-xl text-dark mb-5"> Order Items </h2> <div className="overflow-x-auto"> <table className="w-full"> <thead> <tr className="border-b border-gray-3"> <th className="text-left py-3 px-4 font-medium text-dark"> Product </th> <th className="text-center py-3 px-4 font-medium text-dark"> Unit Price </th> <th className="text-center py-3 px-4 font-medium text-dark"> Quantity </th> <th className="text-right py-3 px-4 font-medium text-dark"> Total </th> </tr> </thead> <tbody> {order.items.map((item) => ( <tr key={item.id} className="border-b border-gray-3"> <td className="py-4 px-4"> <Link href={`/product/${item.product.id}`} className="text-dark hover:text-blue duration-200" > {item.product.title} </Link> </td> <td className="text-center py-4 px-4"> {formatCurrency(item.price)} </td> <td className="text-center py-4 px-4"> {item.quantity} </td> <td className="text-right py-4 px-4 font-medium"> {formatCurrency(item.price * item.quantity)} </td> </tr> ))} </tbody> </table> </div> </div> {/* Shipping & Billing Address */} <div className="grid grid-cols-1 sm:grid-cols-2 gap-7.5"> {/* Shipping Address */} <div className="bg-white shadow-1 rounded-[10px] p-4 sm:p-8.5"> <h3 className="font-medium text-lg text-dark mb-4"> Shipping Address </h3> <address className="not-italic text-gray-5 space-y-1"> <p>{shippingAddress.street}</p> <p> {shippingAddress.city}, {shippingAddress.state}{" "} {shippingAddress.zipCode} </p> <p>{shippingAddress.country}</p> </address> </div> {/* Billing Address */} <div className="bg-white shadow-1 rounded-[10px] p-4 sm:p-8.5"> <h3 className="font-medium text-lg text-dark mb-4"> Billing Address </h3> <address className="not-italic text-gray-5 space-y-1"> <p>{billingAddress.street}</p> <p> {billingAddress.city}, {billingAddress.state}{" "} {billingAddress.zipCode} </p> <p>{billingAddress.country}</p> </address> </div> </div> </div> {/* Order Summary - Right Column */} <div className="lg:col-span-1"> <div className="bg-white shadow-1 rounded-[10px] p-4 sm:p-8.5 sticky top-20"> <h3 className="font-medium text-xl text-dark mb-5"> Order Summary </h3> {/* Items Count */} <div className="py-3 border-b border-gray-3 flex justify-between"> <p className="text-gray-5"> Items ({order.items.reduce((sum, item) => sum + item.quantity, 0)}) </p> <p className="font-medium text-dark"> {formatCurrency( order.items.reduce((sum, item) => sum + item.price * item.quantity, 0) )} </p> </div> {/* Shipping */} <div className="py-3 border-b border-gray-3 flex justify-between"> <p className="text-gray-5">Shipping</p> <p className="font-medium text-dark">Free</p> </div> {/* Total */} <div className="py-4 flex justify-between"> <p className="font-bold text-lg text-dark">Total</p> <p className="font-bold text-lg text-blue"> {formatCurrency(order.total)} </p> </div> {/* Next Steps */} <div className="mt-6 pt-6 border-t border-gray-3"> <h4 className="font-medium text-dark mb-3">What's Next?</h4> <ul className="space-y-2 text-sm text-gray-5"> <li className="flex gap-2"> <span className="text-blue">✓</span> <span>Confirmation email sent to {order.user?.email}</span> </li> <li className="flex gap-2"> <span className="text-blue">•</span> <span>Your order is being prepared</span> </li> <li className="flex gap-2"> <span className="text-blue">•</span> <span>You'll receive tracking info soon</span> </li> <li className="flex gap-2"> <span className="text-blue">•</span> <span>Need help? Check your email or contact support</span> </li> </ul> </div> {/* Action Buttons */} <div className="space-y-3 mt-6"> <Link href="/account/orders" className="block w-full text-center bg-blue text-white py-2.5 rounded-md font-medium hover:bg-blue-dark duration-200" > View Order History </Link> <Link href="/shop" className="block w-full text-center bg-gray-1 text-dark py-2.5 rounded-md font-medium hover:bg-gray-3 duration-200 border border-gray-3" > Continue Shopping </Link> </div> </div> </div> </div> </div> </section> </> ); } export default OrderConfirmationPage; |